package com.genexususa.eo.google.test.campaign;

import com.genexususa.eo.google.connection.CampaignManager;
import com.genexususa.eo.google.data.CampaignReport;
import com.genexususa.eo.google.data.GA_CampaignStats;
import com.genexususa.eo.google.data.GA_Report;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import java.io.StringWriter;
import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 * User: Emiliano Martinez
 * Date: 7/10/14
 * Time: 1:41 PM
 * To change this template use File | Settings | File Templates.
 */
public class ConsumeGetCampaignStats {

    public static void main(String[] args){

        CampaignManager cm = new CampaignManager();

        cm.SetClientId("2244382751");
        ArrayList<GA_CampaignStats> stats = cm.GetCampaignStats("191893959");
        cm.Finalize();
        GA_Report report = new GA_Report();

        for (GA_CampaignStats stat : stats){

            CampaignReport campaignReport = new CampaignReport();
            campaignReport.AdServingOptimizationStatus = stat.AdServingOptimizationStatus;
            campaignReport.BidCeiling = stat.BidCeiling;
            campaignReport.BiddingStrategyType = stat.BiddingStrategyType;
            campaignReport.BidType = stat.BidType;
            campaignReport.BudgetId = stat.BudgetId;
            campaignReport.EndDate = stat.EndDate;
            campaignReport.EnhancedCpcEnabled = stat.EnhancedCpcEnabled;
            campaignReport.FrequencyCapMaxImpressions = stat.FrequencyCapMaxImpressions;
            campaignReport.Id = stat.Id;
            campaignReport.Level = stat.Level;
            campaignReport.Name = stat.Name;
            campaignReport.PricingMode = stat.PricingMode;
            campaignReport.StartDate = stat.StartDate;
            campaignReport.Status = stat.Status;
            campaignReport.TargetContentNetwork = stat.TargetContentNetwork;
            campaignReport.TargetGoogleSearch = stat.TargetGoogleSearch;
            campaignReport.TargetPartnerSearchNetwork = stat.TargetPartnerSearchNetwork;
            campaignReport.TargetSearchNetwork = stat.TargetSearchNetwork;
            campaignReport.TimeUnit = stat.TimeUnit;
            campaignReport.GeoTargetNegativeType = stat.GeoTargetNegativeType;
            campaignReport.GeoTargetPositiveType = stat.GeoTargetPositiveType;
            campaignReport.KeywordMatch = stat.KeywordMatch;
            campaignReport.RealTimeBidding = stat.RealTimeBidding;
            campaignReport.AdvertisingChannelType = stat.AdvertisingChannelType;
            campaignReport.BiddingStrategyId = stat.BiddingStrategyId;
            campaignReport.BiddingStrategyName = stat.BiddingStrategyName;

            report.Campaigns.add(campaignReport);
        }

        try {

            String result = "";
            JAXBContext contextObj = JAXBContext.newInstance(GA_Report.class);
            Marshaller marshallerObj = contextObj.createMarshaller();
            marshallerObj.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
            StringWriter sw = new StringWriter();
            marshallerObj.marshal(report, sw);
            result = sw.getBuffer().toString();
            System.out.println(result);

        } catch (Exception exc) {
            exc.printStackTrace();
        }

    }
}
